home *** CD-ROM | disk | FTP | other *** search
/ Enter 2006 September / Enter 09 2006.iso / Internet / SpamExperts Home 1.1 / SpamExperts Home.exe / lib / spamexperts.modules / spamexperts / spf_wrapper.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2006-07-14  |  3.4 KB  |  103 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.4)
  3.  
  4. import dns
  5. import dns.resolver as dns
  6. import dns.exception as dns
  7. import spf
  8. spf.RESULTS = {
  9.     '+': 'pass',
  10.     '-': 'deny',
  11.     '?': 'unknown',
  12.     '~': 'softfail',
  13.     'pass': 'pass',
  14.     'deny': 'deny',
  15.     'unknown': 'unknown' }
  16. spf.EXPLANATIONS = {
  17.     'pass': 'sender SPF verified',
  18.     'deny': 'access denied',
  19.     'unknown': 'SPF unknown',
  20.     'softfail': 'sender SPF not verified' }
  21.  
  22. def check(i, s, h):
  23.     if i.startswith('127.'):
  24.         return ('pass', 250, 'local connections always pass')
  25.     
  26.     
  27.     try:
  28.         q = spf_query(i = i, s = s, h = h)
  29.         return q.check(q.dns_spf(q.d))
  30.     except dns.exception.DNSException:
  31.         return ('error', 450, 'SPF DNS Error')
  32.  
  33.  
  34.  
  35. class spf_query(spf.query):
  36.     
  37.     def validated_ptrs(self, i):
  38.         '''Figure out the validated PTR domain names for a given IP
  39. \t\taddress.
  40. \t\t'''
  41.         return _[1]
  42.  
  43.     
  44.     def dns_a(self, domainname):
  45.         raw = spf.query.dns_a(self, domainname)
  46.         return [ str(a) for a in raw ]
  47.  
  48.     
  49.     def dns_mx(self, domainname):
  50.         '''Get a list of IP addresses for all MX exchanges for a
  51. \t\tdomain name.
  52. \t\t'''
  53.         return [ str(a) for mx in self.dns(domainname, 'MX') for a in self.dns_a(str(mx.exchange)) ]
  54.  
  55.     
  56.     def dns_txt(self, domainname):
  57.         result = []
  58.         for a in self.dns(domainname, 'TXT'):
  59.             if hasattr(a, 'strings'):
  60.                 []([ t for t in a.strings ])
  61.                 continue
  62.             []
  63.         
  64.         return result
  65.  
  66.     
  67.     def dns(self, name, qtype):
  68.         """DNS query.
  69.  
  70. \t\tIf the result is in cache, return that.  Otherwise pull the
  71. \t\tresult from DNS, and cache ALL answers, so additional info
  72. \t\tis available for further queries later.
  73.  
  74. \t\tCNAMEs are followed.
  75.  
  76. \t\tIf there is no data, [] is returned.
  77.  
  78. \t\tpre: qtype in ['A', 'AAAA', 'MX', 'PTR', 'TXT', 'SPF']
  79. \t\tpost: isinstance(__return__, types.ListType)
  80. \t\t"""
  81.         result = self.cache.get((name, qtype))
  82.         cname = None
  83.         if not result:
  84.             answers = dns.resolver.query(name, qtype)
  85.             for a in answers.response.answer:
  86.                 k = (name, qtype)
  87.                 v = a.items
  88.                 for part in v:
  89.                     if part.rdtype == 5:
  90.                         cname = str(part.target)
  91.                         break
  92.                         continue
  93.                 
  94.             
  95.             result = self.cache.get((name, qtype), [])
  96.         
  97.         if not result and cname:
  98.             result = self.dns(cname, qtype)
  99.         
  100.         return result
  101.  
  102.  
  103.